<?php

class CCustomTheme extends CTheme
{
    private $_name;
    private $_basePath;
    private $_baseUrl;
    private $_themesUrl;
    public  $themeUrl;
    public  $resourceUrl;
    public  $jsUrl;
    public  $cssUrl;
    public  $imgUrl;
        
    public function __construct($name, $basePath, $baseUrl)
    {
        $this->_name     = $name;
        $this->_baseUrl  = $baseUrl;
        $this->_basePath = $basePath;

        parent::__construct($name, $basePath, $baseUrl);
    }

    public function getViewPath()
    {
        return $this->_basePath.DIRECTORY_SEPARATOR.'templates/actions';
    }
    
    public function getThemesUrl()
    {
        return '/themes';
    }

    public function getLayoutFile($controller,$layoutName)
	{
		$moduleViewPath=$basePath=$this->getViewPath();
		$module=$controller->getModule();
		if(empty($layoutName))
		{
			while($module!==null)
			{
				if($module->layout===false)
					return false;
				if(!empty($module->layout))
					break;
				$module=$module->getParentModule();
			}
			if($module===null)
				$layoutName=Yii::app()->layout;
			else
			{
				$layoutName=$module->layout;
				$moduleViewPath.='/'.$module->getId();
			}
		}
		else if($module!==null)
			$moduleViewPath.='/'.$module->getId();

        $sLayoutFile = dirname($moduleViewPath).'/layouts';

        if ( $module )
        {
            $sLayoutFile = dirname(dirname($moduleViewPath)).'/layouts';
        }

		return $controller->resolveViewFile($layoutName, $sLayoutFile, $basePath, $moduleViewPath);
	}
}
